#include "idisposable.h"
#include "Debug.h"

idisposable::idisposable()
{
	usage = 1;
}
idisposable::~idisposable()
{
	// All the work happens in the derived destructor.
}
void idisposable::dereference(idisposable **object_ptr)
{
	DEBUG_FUNCTION
	DEBUG_LINE
	if ((object_ptr == nullptr) || ((*object_ptr) == nullptr)) {
		DEBUG_LINE
		return; // The object is already deleted.
	}
	DEBUG_LINE
	idisposable *item;	
	item = *object_ptr;
	DEBUG_LINE
	item->usage--;
	DEBUG_LINE
	if (item->usage <= 0) {
		DEBUG_LINE
		delete item;
	}
	DEBUG_LINE
	(*object_ptr) = nullptr;
	DEBUG_LINE
}